<%@include file="/WEB-INF/common/taglibs.jsp"%>



 
<c:if test="${fn:length(languages) gt 1}">
<c:choose>
   <c:when test="${nameOnly ne null }">
   		<c:if test="${showName eq null}" >
   		      <c:set var="showName" value="true" />
   		</c:if>
   		<c:if test="${showBody eq null}" >
	      <c:set var="showBody" value="false" />
   		</c:if>

   </c:when>
   <c:otherwise>
   
   		<c:if test="${showName eq null}" >
   		      <c:set var="showName" value="false" />
   		</c:if>
   		<c:if test="${showBody eq null}" >
	      <c:set var="showBody" value="true" />
   		</c:if>
   </c:otherwise>
</c:choose>
 <div class="row-fluid meta-div">
<div class="span12">
	<div class="box gradient">
	 
		<div class="title">
				<h4>
				<span>Meta Info </span> <span class="box-form right"> </span>
				
				<span class="box-form right metaInfo_bar"><a href="#" class="btn btn-mini addMetaInfo">Add Meta Info</a></span>
 				</h4>
 				<a href="#" class="minimize"> </a>
			</div>
		 <div class="content scrollable clearfix">
		<table class="table table-bordered table-vertical-centre metaInfoTable">
			<thead>
				<tr>
					<th><a class="select_all"><span class="icomoon-icon-checkmark-2"></span></a></th>
<c:if test="${showName}">
<th> Name </th>
</c:if>
<th>Language </th>
<c:if test="${showBody}">
<th>Title </th>
<th>Meta Keywords </th>
<th>Meta Title </th>
<th>Meta Description </th>
<th>Meta Og</th>
<th>Meta Seo</th>
</c:if>

 					<th>Action</th>
				</tr>
			</thead>
		</table>
		</div>
	 
</div>
 </div>











<div id="metaInfoDiv" class="modal hide fade"  selector=".metaInfoTable" style="display: none; ">
	<div class="modal-header">
		<button type="button" class="close" data-dismiss="modal">
			<span class="icon12 minia-icon-close"></span>
		</button>
		<h3>	Meta Info  </h3>
	</div>
 
	<div class="modal-body">
		<input type="hidden" name="action" >
<c:if test="${showName}">
<!--name --><div class="form-row row-fluid"><div class="span12"><div class="row-fluid"><label class="form-label span3" for="name">Name :</label><input class="span8" id="name" name="name"   type="text" value="${entity.name}" /></div></div></div>
</c:if>
<!--language --><div class="form-row row-fluid"><div class="span12"><div class="row-fluid"><label class="form-label span3">Language :</label><div class="span8 controls"><select name="languageId"><c:if test="${not empty languages}"><c:forEach var="single" items="${languages}"><option value="${single.id}">${single.language}</option></c:forEach></c:if></select></div></div></div></div>
<c:if test="${showBody}">
<!--title --><div class="form-row row-fluid"><div class="span12"><div class="row-fluid"><label class="form-label span3" for="title">Title :</label><input class="span8" id="title" name="title"   type="text"  /></div></div></div>
<!--metaKeywords --><div class="form-row row-fluid"><div class="span12"><div class="row-fluid"><label class="form-label span3" for="metaKeywords">Meta Keywords :</label><input class="span8" id="metaKeywords" name="metaKeywords"   type="text"  /></div></div></div>
<!--metaTitle --><div class="form-row row-fluid"><div class="span12"><div class="row-fluid"><label class="form-label span3" for="metaTitle">Meta Title :</label><input class="span8" id="metaTitle" name="metaTitle"   type="text" /></div></div></div>
<!--metaDescription --><div class="form-row row-fluid"><div class="span12"><div class="row-fluid"><label class="form-label span3" for="metaDescription">Meta Description :</label><input class="span8" id="metaDescription" name="metaDescription"   type="text" /></div></div></div>
<div class="form-row row-fluid"><div class="span12"><div class="row-fluid"><label class="form-label span3" for="metaOg">Meta Og :</label><textarea name="metaOg" class="span8 limit elastic" id="metaOg" rows="3" cols="5"></textarea></div></div></div>
<div class="form-row row-fluid"><div class="span12"><div class="row-fluid"><label class="form-label span3" for="metaSeo">Meta Seo :</label><textarea name="metaSeo" class="span8 limit elastic" id="metaSeo" rows="3" cols="5"></textarea></div></div></div>
</c:if>
</div>

	 
	<div class="modal-footer">
		<a href="#" class="btn" data-dismiss="modal">Close</a>
		<a href="#" class="btn btn-primary modal-submit">Save changes</a>
	</div>

</div>

</div>

<script>
 
 

$(document).ready(function(){
	$("#metaInfoDiv").appendTo($("body"));
	
	var del = {
			id : 'metaInfoDel',
			text  : 'Del',
			domain : "Meta Info",
			operation : "Del",
			url : "${ctx}/admin/meta-info/del/",
			selector : ".metaInfo_bar",
			selects  : $('.metaInfoTable'),
	  
	};
	johnny.tableBtn(del);
	
 	
	
	$('.addMetaInfo').click(function(){
	$("#metaInfoDiv").find("div.modal-body").find("input,select,textarea,checkbox").not("[name=action],[type=hidden]").not("[type=radio]").each(function(step,value){
	 									$(value).val("");
	 							});
	
	
	
	 $("#metaInfoDiv input[name='action']").val("${ctx}/admin/meta-info/${entity.id}/create/"+meta_type+"/");
 	 $("#metaInfoDiv").modal('show');
  });
	
	  $(document).delegate('.metaInfoTable .icomoon-icon-pencil', 'click', function(event) {
		  
		  	var id = $(this).parent().attr("dataid");
			$.ajax({
				url : "${ctx}/admin/meta-info/"+id+"/edit/",
				type : "GET",
				dataType : "json",
				success : function(data){		
					if(data && data.state && (data.state.indexOf("ERROR") != -1)){
						johnny.error(data.message);
						return;
					}else{
							var entity = data.entity;
							
							
							
 							$("#metaInfoDiv").find("div.modal-body").find("input,select,textarea,checkbox").not("[name=action],[type=hidden]").each(function(step,value){
									var name = $(value).attr("name");
									if ($(value).is(':radio')) {
										if (""+entity[name] ===""+$(value).val()){
  												$(value).attr("checked","checked");
   											}else{
   												$(value).removeAttr("checked");
 																			
 											}
										
									}else{
 									if (entity[name]|| entity[name]===0){
										$(value).val(entity[name]);
 										$(value).uniform();
 									}else if (name.match(/Id$/)){
										var pro = name.substring(0,name.length-2);
										if (entity[pro] &&entity[pro].id){
											$(value).val(entity[pro].id);
	 										$(value).uniform();
 										}
 									
									}
									else{
 										$(value).val("");
									}}
								
							});
							
							var x = $("#metaInfoDiv").find("div.modal-body").find('input[type="radio"]').uniform();
   							$("#metaInfoDiv input[name='action']").val("${ctx}/admin/meta-info/"+id+"/edit/");
     	    				$("#metaInfoDiv").modal('show');
 					}
				}
			});		  
 
	     
	    });
	var recordColumn = ['','language','title','metaKeywords','metaTitle','metaDescription','metaOg'];
	
	 $('.metaInfoTable').dataTable({
		"bLengthChange" : true,
		"aoColumnDefs" : [ {
			'bSortable' : false,
			'aTargets' : [0]
		} ],
 		"sAjaxSource" : '${ctx}/admin/meta-info/${entity.id}/'+meta_type+'/',
		"createQueryData" : function (aoData){
				return	johnny.initQueryData(aoData, recordColumn);
		},
		"createResult" : function (json, echo){
 			var dataArray = new Array();
			for ( var i = 0; i < json.result.length; i++) {
				var subArray = new Array();
				var value = johnny.getForSelect(json.result[i].id);
				subArray.push(value);
				
				<c:if test="${showName}">
				subArray.push(json.result[i].name)
				</c:if>
				
 				if (json.result[i].language){
					subArray.push(json.result[i].language.language)					
				}else{
					subArray.push("");					
				}
 				<c:if test="${showBody}">
subArray.push(json.result[i].title)
subArray.push(json.result[i].metaKeywords)
subArray.push(json.result[i].metaTitle)
subArray.push(json.result[i].metaDescription)
subArray.push(json.result[i].metaOg);
subArray.push(json.result[i].metaSeo);
</c:if>
   				var conf = [{
					link : 'javascript:void(1)',
					dataId : json.result[i].id,
					text : 'edit',
					css  : 'icomoon-icon-pencil'
				} 
				
				];
				subArray.push(johnny.getGridLink(conf)); 
  				dataArray.push(subArray);
			}
			return {
				sEcho : echo,
				iTotalRecords : json.totalCount,
				iTotalDisplayRecords : json.totalCount,
				aaData : dataArray
			};
		}		
	});
	 
	
	
	
	
});


</script>
 </c:if>   
 
 